﻿using MTQ.BLL;
using MTQ.Common;
using MTQ.Model;
using MTQ.Web.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MTQ.Web.Controllers
{
    public class HomeController : BaseController
    {
        [AdminLayoutAttribute]
        public ActionResult Index()
        {
            //ViewBag.Message = "修改此模板以快速启动你的 ASP.NET MVC 应用程序。";
            //if (CurrentUserInfo == null) {
            //    return null;
            //}

            var name = Session["CultureInfoName"].ToString().ToLower();
            string cn = "";
            if (name.IndexOf("cn") > -1 || string.IsNullOrEmpty(name))
            {
                cn = "language_selected";
            }
            string en = "";
            if (name.IndexOf("en") > -1)
            {
                en = "language_selected";
            }

            ViewBag.CN = cn;
            ViewBag.EN = en;

            ViewBag.Base_ModifyPassword = Base_LocalService.GetWord("Base_ModifyPassword", CultureInfoName);
            ViewBag.Base_Logout = Base_LocalService.GetWord("Base_Logout", CultureInfoName);
            ViewBag.Base_CloseCurrent = Base_LocalService.GetWord("Base_CloseCurrent", CultureInfoName);
            ViewBag.Base_CloseOther = Base_LocalService.GetWord("Base_CloseOther", CultureInfoName);
            ViewBag.Base_CloseAll = Base_LocalService.GetWord("Base_CloseAll", CultureInfoName);
            ViewBag.UserName = CurrentUserInfo.User_RealName;


           

            return View();
        }

       

        public ActionResult DashBoard()
        {

            ViewBag.DashBoard_ProjectDuration = Base_LocalService.GetWord("DashBoard_ProjectDuration", CultureInfoName);
            ViewBag.DashBoard_ProjectCategory = Base_LocalService.GetWord("DashBoard_ProjectCategory", CultureInfoName);
            ViewBag.DashBoard_ProjectAll = Base_LocalService.GetWord("DashBoard_ProjectAll", CultureInfoName);
            ViewBag.DashBoard_Location = Base_LocalService.GetWord("DashBoard_Location", CultureInfoName);
            ViewBag.DashBoard_ProjectQTYResult = Base_LocalService.GetWord("DashBoard_ProjectQTYResult", CultureInfoName);
            ViewBag.DashBoard_Department = Base_LocalService.GetWord("DashBoard_Department", CultureInfoName);
            ViewBag.ProjectDashboard = Base_LocalService.GetWord("ProjectDashboard", CultureInfoName);
            ViewBag.TitleProjectAll = Base_LocalService.GetWord("TitleProjectAll", CultureInfoName);
            ViewBag.TitleDepartment = Base_LocalService.GetWord("TitleDepartment", CultureInfoName);
            ViewBag.TitleLocation = Base_LocalService.GetWord("TitleLocation", CultureInfoName);
            ViewBag.TitleProject = Base_LocalService.GetWord("TitleProject", CultureInfoName);
            ViewBag.TitleProjectOpenClose = Base_LocalService.GetWord("DashBoard_ProjectOpenClose", CultureInfoName);


            return View();
        }


        public ActionResult TestPage()
        {

            //return PartialView();
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "你的应用程序说明页。";

            return View();
        }


        public ActionResult ForbidEdit()
        {

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "你的联系方式页。";

            return View();
        }
        public ActionResult Test()
        {

            return View();
        }

        public ActionResult EditPassword()
        {

            return View();
        }
        public ActionResult Refresh()
        {
            Base_LocalService ls = new Base_LocalService();
            ls.RefreshLanguage();
            return View();
        }

        public ActionResult LoginOut()
        {           

            Session.RemoveAll();
            Session.Clear();
            return Redirect("/Login/Index");

        }

        public ActionResult Menu()
        {

            LayuiMenu layuimenu = new LayuiMenu();

            Base_MenuService bms = new Base_MenuService();
            Base_Menu listHome = bms.MenuAll(null, 0).First();         

            List<Guid> usermenuids = SessionHelper.GetSessionListMenu(this);
            layuimenu.homeInfo = new LayuiMenuInfo() { title = Base_LocalService.GetWord(listHome.Menu_Title, CultureInfoName), href = listHome.Menu_NavigateUrl };
            layuimenu.logoInfo = new LayuiMenuInfo() { title = "", href = "", image = "Content/logo1.png" };

            List<LayuiMenuInfo> menuinfo = new List<LayuiMenuInfo>() { };
            LayuiMenuInfo first = new LayuiMenuInfo();
            first.child = bms.UserMenu(null, usermenuids, CultureInfoName);
            first.title = "System";
            first.icon = "fa fa-address-book";
            first.href = "";
            first.target = "_self";
            menuinfo.Add(first);

            layuimenu.menuInfo = menuinfo;


          

            return Json(layuimenu, JsonRequestBehavior.AllowGet);
        }

        public ActionResult SettingLanguage()
        {
            var lk = GetRequestQueryString("language");

            Session["CultureInfoName"] = lk;


            new Base_LocalUserService().SetUser(CurrentUserInfo.User_Id, lk);

            return Json("OK");

        }
    }
}
